package com.suse.boss.mapper;

import com.suse.boss.entity.ChatMsgs;
import com.suse.boss.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ChatMsgsMapper {

    @Select( "select * from chatmsgs where `from`=#{id} or `to`=#{id} order by creatTime" )
    public List<ChatMsgs> listmsgs(@Param( "id" ) Long id);

    @Select( "select * from chatmsgs" )
    public List<ChatMsgs> listall();


    @Options(useGeneratedKeys = true,keyProperty = "_id",keyColumn = "_id")//加入该注解可以保持对象后，查看对象插入id
    @Insert( "insert into chatmsgs (`from`,`to`,content,creatTime,chat_id) values (#{chatMsgs.from},#{chatMsgs.to},#{chatMsgs.content},#{chatMsgs.creatTime},#{chatMsgs.chat_id})" )
    public int saveChatMsgs(@Param( "chatMsgs" ) ChatMsgs chatMsgs);

    @Update( "update chatmsgs set `read`=true where `from`=#{from} and `to`=#{to} " )
    public int readMsgs(Long from,Long to);
    @Select( "select count(*) from chatmsgs where `from`=#{from} and `to`=#{to} and `read`=false " )
    public int readFalse(Long from,Long to);
}
